package com.kczd.jinlan.db.shopcar;

import android.content.ContentValues;
import android.util.Log;

import com.kczd.jinlan.model.ShoppingCartBean;

import org.litepal.crud.DataSupport;

/**
 * zhangy
 * 订单的CRUD
 * Created by Administrator on 2017/5/24.
 */

public class DbUtils {


    /**
     * 修改数据库的方法
     */
    public static void updateData(int cid,int count)
    {
        ContentValues values = new ContentValues();
        values.put("count", count);
        DataSupport.update(ShoppingCartBean.class, values, cid);
    }

    /**
     * 添加数据的方法
     */
    public static void addData(String title,String img,String weight,String Spec_key,String Spec_name ,String price,int cid,int count)
    {
        ShoppingCartBean shoppingCartBean= new ShoppingCartBean();
        shoppingCartBean.setShoppingName(title);
        shoppingCartBean.setSpec_key(Spec_key);
        shoppingCartBean.setSpec_name(Spec_name);
        shoppingCartBean.setDesc(weight+Spec_key+Spec_name);
        shoppingCartBean.setImageUrl(img);
        shoppingCartBean.setPrice(price);
        shoppingCartBean.setCid(cid);
        shoppingCartBean.setCount(count);
        Log.d("TAG", "news id is " + shoppingCartBean.getId());
        shoppingCartBean.save();
        Log.d("TAG", "news id is " + shoppingCartBean.getId());
    }

    /**
     * 删除数据的方法
     */

    public static void  deleteData(int positon)
    {
        int deleteCount = DataSupport.delete(ShoppingCartBean.class, positon);
        Log.d("TAG", "delete count is " + deleteCount);
    }

//    /**
//     * 修改数据库的方法
//     */
//    public static void updateData(String cid,int count)
//    {
//        ContentValues values = new ContentValues();
//        values.put("count", count+1);
//        DataSupport.updateAll(ShoppingCartBean.class, values, "cid = ?",cid);
//    }

}
